<?php
/**
 * Development Bar 
 *
 * This plugin will add a little bar to the bottom of your webpage
 * while you browse your webpage in development mode.
 * 
 * It will show you:
 * - Current ZF version that is in use.
 * - Peak amount of memory used for the current page.
 * - Avarage dispatch time for the last 100 page views.
 * - The amount of time the current dispatch is slower 
 *   or faster than the avarage 100 last dispatches.
 * - Amount and information about known Cookies
 * - Number of executed SQL-queries and the time it took
 * - Number of SQL-queries executed per second
 * - The longest SQL-query in a javascript alert window
 *  
 * @todo Use a canvas to generate the arrows. 
 * @todo Add a log reader that tails the error log for -n lines
 * @todo Organize categories in folding tabs
 *
 * @uses      Zend_Controller_Plugin_Abstract
 * @category  My
 * @package   My_Controller
 * @copyright Copyright (C) 2009 - Mathias Johansson
 * @author    Mathias Johansson <hi@mathiasjohansson.se>
 * @link      http://www.mathiasjohansson.se
 * @license   New BSD {@link http://framework.zend.com/license/new-bsd}
 * @version   $Id: $
 */
class Wmp_Controller_Plugin_DebugBar extends Zend_Controller_Plugin_Abstract
{
    public function __construct() {
        	
    }
    
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        
    }
 	
    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
        $config = Zend_Registry::get('config');
    	$registred_template = Zend_Registry::get('template');
    	$layoutName = Zend_Registry::get('layoutName');
    	$translate =  Zend_Registry::get('Zend_Translate');
    	
        if(!$this->getRequest()->isXmlHttpRequest()) {              
            $moduleName = $request->getModuleName();
            $controllerName = $request->getControllerName();
            $actionName = $request->getActionName();
            $controllerPath = "controller path";
            $templateName= $registred_template;
            $templatePath= $config->path->public->dir.'/templates/'.$registred_template.'/layouts/'.$layoutName.'.'.$config->layouts->suffix;          
            $sDebug = '<br /><br /><br /><style type="text/css">#debugbar{background-color: #eee;border-top: 1px dashed #ccc;text-align: left;font-size:10px;color:#CC0000;font-family:sans-serif;padding: 5px;width: 100%;position:fixed; left:0px; bottom:20px;}.c{ float:left;padding-right:8px;}.d{float:left;color:#666;padding-right:8px;}</style>'; 
            
            $sDebug .= '<div id="debugbar">';
            $sDebug .= '<div class="c"><strong>Espace:</strong> ' . $translate->getLocale().'_'.$request->getParam('region') . '</div><div class="d">|</div>';
            $sDebug .= '<div class="c"><strong>Module:</strong> ' . $moduleName . '</div><div class="d">|</div>';
            $sDebug .= '<div class="c"><strong><a href="' . $controllerPath . '">Controller: </strong> '. $controllerName .' </a></div><div class="d">|</div>';
            $sDebug .= '<div class="c"><strong>Action:</strong> ' . $actionName . '</div><div class="d">|</div>';
            $sDebug .= '<div class="c"><strong>Template help:</strong> ' . $templatePath . '</div><div class="d">|</div>';
            $sDebug .= '<div class="c"><strong>Css help:</strong> ' . $templatePaths . '</div><div class="d">|</div>';
            $sDebug .= '<div class="c"><strong>Images help :</strong> ' . $templatePaths . '</div><div class="d">|</div>';
            $sDebug .= '<div class="c"><strong>Voir mon livre pour les help :</strong> ' . $templatePaths . '</div><div class="d">|</div>';
            $sDebug .= '</div>';
                        
            $this->getResponse()->setBody(
            	$this->getResponse()->getBody('default') . $sDebug,
            	'default'
            );
        }
    }
}